package com.example.hellowordl;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.example.hellowordl.R;

public class ProfileEditActivity extends AppCompatActivity {

    private static final int SELECT_INTEREST_REQUEST_CODE = 1001;

    private TextView btnBack;
    private TextView tvUsernameDisplay;
    private TextView tvInterestSelector;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile_edit);

        btnBack = findViewById(R.id.btn_back);
        tvUsernameDisplay = findViewById(R.id.tv_username_display);
        tvInterestSelector = findViewById(R.id.tv_interest_selector);

        String username = getIntent().getStringExtra("USERNAME_KEY");
        tvUsernameDisplay.setText("用户名" + username);

        setupListeners();
    }

    private void setupListeners() {
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        tvInterestSelector.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ProfileEditActivity.this, InterestSelectionActivity.class);
                startActivityForResult(intent, SELECT_INTEREST_REQUEST_CODE);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == SELECT_INTEREST_REQUEST_CODE && resultCode == RESULT_OK) {
            if (data != null) {
                String selectedInterests = data.getStringExtra("INTEREST_RESULT_KEY");
                if (selectedInterests != null && !selectedInterests.isEmpty()) {
                    tvInterestSelector.setText("兴趣" + selectedInterests);
                } else {
                    tvInterestSelector.setText("兴趣未选择");
                }
            }
        }
    }
}
